{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "___\n",
    "\n",
    "<a href='https://www.udemy.com/user/joseportilla/'><img src='../Pierian_Data_Logo.png'/></a>\n",
    "___\n",
    "<center><em>Content Copyright by Pierian Data</em></center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# if, elif, else Statements\n",
    "\n",
    "<code>if</code> Statements in Python allows us to tell the computer to perform alternative actions based on a certain set of results.\n",
    "\n",
    "Verbally, we can imagine we are telling the computer:\n",
    "\n",
    "\"Hey if this case happens, perform some action\"\n",
    "\n",
    "We can then expand the idea further with <code>elif</code> and <code>else</code> statements, which allow us to tell the computer:\n",
    "\n",
    "\"Hey if this case happens, perform some action. Else, if another case happens, perform some other action. Else, if *none* of the above cases happened, perform this action.\"\n",
    "\n",
    "Let's go ahead and look at the syntax format for <code>if</code> statements to get a better idea of this:\n",
    "\n",
    "    if case1:\n",
    "        perform action1\n",
    "    elif case2:\n",
    "        perform action2\n",
    "    else: \n",
    "        perform action3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## First Example\n",
    "\n",
    "Let's see a quick example of this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "It was true!\n"
     ]
    }
   ],
   "source": [
    "if True:\n",
    "    print('It was true!')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's add in some else logic:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I will be printed in any case where x is not true\n"
     ]
    }
   ],
   "source": [
    "x = False\n",
    "\n",
    "if x:\n",
    "    print('x was True!')\n",
    "else:\n",
    "    print('I will be printed in any case where x is not true')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Multiple Branches\n",
    "\n",
    "Let's get a fuller picture of how far <code>if</code>, <code>elif</code>, and <code>else</code> can take us!\n",
    "\n",
    "We write this out in a nested structure. Take note of how the <code>if</code>, <code>elif</code>, and <code>else</code> line up in the code. This can help you see what <code>if</code> is related to what <code>elif</code> or <code>else</code> statements.\n",
    "\n",
    "We'll reintroduce a comparison syntax for Python."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome to the bank!\n"
     ]
    }
   ],
   "source": [
    "loc = 'Bank'\n",
    "\n",
    "if loc == 'Auto Shop':\n",
    "    print('Welcome to the Auto Shop!')\n",
    "elif loc == 'Bank':\n",
    "    print('Welcome to the bank!')\n",
    "else:\n",
    "    print('Where are you?')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note how the nested <code>if</code> statements are each checked until a True boolean causes the nested code below it to run. You should also note that you can put in as many <code>elif</code> statements as you want before you close off with an <code>else</code>.\n",
    "\n",
    "Let's create two more simple examples for the <code>if</code>, <code>elif</code>, and <code>else</code> statements:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome Sammy!\n"
     ]
    }
   ],
   "source": [
    "person = 'Sammy'\n",
    "\n",
    "if person == 'Sammy':\n",
    "    print('Welcome Sammy!')\n",
    "else:\n",
    "    print(\"Welcome, what's your name?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome George!\n"
     ]
    }
   ],
   "source": [
    "person = 'George'\n",
    "\n",
    "if person == 'Sammy':\n",
    "    print('Welcome Sammy!')\n",
    "elif person =='George':\n",
    "    print('Welcome George!')\n",
    "else:\n",
    "    print(\"Welcome, what's your name?\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Indentation\n",
    "\n",
    "It is important to keep a good understanding of how indentation works in Python to maintain the structure and order of your code. We will touch on this topic again when we start building out functions!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
